package demo.controller;

import demo.model.CustomIdentity;
import demo.entity.User;
import demo.entity.Issue;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.seam.annotations.Create;
import org.jboss.seam.annotations.In;


import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.component.UIData;
import javax.faces.event.ActionEvent;
import javax.faces.model.SelectItem;
import javax.faces.validator.ValidatorException;
import java.util.Map;
import java.util.List;
import demo.entity.UploadedFile;
import java.util.ArrayList;
import org.richfaces.model.UploadItem;



/**
 * Glue code to bind Add New Issue Service with the view framework (Seam). This class contains
 * a default implementation of the action methods. Please avoid reimplmenting the action methods in this class.
 * The purpose of this class is to declare properties which can be bound to the UI.
 * 
  * This page provides a form for submitting a new issue.
  *
 * Automatically generated by clickframes
 * 
 * @author Vineet Manohar
 */
public abstract class GeneratedNewIssueController extends Controller {
    @In("#{issueDao}") 
    protected demo.dao.IssueDao issueDao;

    @In("#{issueService}") 
    protected demo.entity.service.IssueService issueService;


    public User getLoggedInUser() {
        return identity.getUser();
    }



    /** $!Issue - INPUT */
    protected Issue issue;

    /** 
     * Get Issue
     *  
     * @return Issue
     */
    public Issue getIssue() {
       return this.issue;
    }

    /**
     * Set Issue
     *
     * @param issue
     */
    public void setIssue(Issue issue) {
        this.issue = issue;
    }


    protected void initIssue() {
        // if ${outputList.id} has not been initialized, initialize it now
        if (getIssue() == null) {
            setIssue(loadIssue());
        }
        
     }

    protected Issue loadIssue() {
    return null;
    }

    protected void reloadIssue() {
        clearIssue();
        loadIssue();
    }

    protected void clearIssue() {
        setIssue(null);
    }
 
    
	@SuppressWarnings("unused")
	private static final Log logger = LogFactory.getLog(GeneratedNewIssueController.class);

	@In
	protected CustomIdentity identity;

    @Create
    public void init() {

        initNewIssueFormPriority();
        initNewIssueFormAssignee();
        initNewIssueFormEnvironment();

        // initialize all file inputs
        // newIssueFormAttachment = new UploadedFile();
          // all inputs initialized here 
    }




	/**
	 * This method should be called before the page is loaded
	 * 
	 * All the page parameters should be consumed in this method
	 */    
    public String processPageParameters() {


          // if you need to add more code, override this method in the child class

        return null;
    }


	/** Issue Title
	 *
 	 * Issue Title
 	 */
   
	protected String newIssueFormTitle;

  	@org.hibernate.validator.NotNull(message="Please enter an issue title.")
  	public String getNewIssueFormTitle() {
	   return this.newIssueFormTitle;
	}

	public void setNewIssueFormTitle(String newIssueFormTitle) {
		this.newIssueFormTitle = newIssueFormTitle;
	}
	/** Description
	 *
 	 * Description
 	 */
   
	protected String newIssueFormDescription;

  	@org.hibernate.validator.NotNull(message="Please enter a description for your issue.")
  	public String getNewIssueFormDescription() {
	   return this.newIssueFormDescription;
	}

	public void setNewIssueFormDescription(String newIssueFormDescription) {
		this.newIssueFormDescription = newIssueFormDescription;
	}




    /** $!${input.description} */
    private UploadedFile newIssueFormAttachment;

    /** 
     * Get Attachment
     *  
     * @return Attachment
     */
    public UploadedFile getNewIssueFormAttachment() {
       return this.newIssueFormAttachment;
    }

    /**
     * Set Attachment
     *
     * @param newIssueFormAttachment
     */
    public void setNewIssueFormAttachment(UploadedFile newIssueFormAttachment) {
        this.newIssueFormAttachment = newIssueFormAttachment;
    }



    /** $!${input.description} Data */
    private java.io.InputStream newIssueFormAttachmentInputStream;

    /** 
     * Get Attachment Data
     *  
     * @return Attachment Data
     */
    public java.io.InputStream getNewIssueFormAttachmentInputStream() {
       return this.newIssueFormAttachmentInputStream;
    }

    /**
     * Set Attachment Data
     *
     * @param newIssueFormAttachmentInputStream
     */
    public void setNewIssueFormAttachmentInputStream(java.io.InputStream newIssueFormAttachmentInputStream) {
        this.newIssueFormAttachmentInputStream = newIssueFormAttachmentInputStream;
    }



    /** $!${input.description} ContentType */
    private String newIssueFormAttachmentContentType;

    /** 
     * Get Attachment ContentType
     *  
     * @return Attachment ContentType
     */
    public String getNewIssueFormAttachmentContentType() {
       return this.newIssueFormAttachmentContentType;
    }

    /**
     * Set Attachment ContentType
     *
     * @param newIssueFormAttachmentContentType
     */
    public void setNewIssueFormAttachmentContentType(String newIssueFormAttachmentContentType) {
        this.newIssueFormAttachmentContentType = newIssueFormAttachmentContentType;
    }



    /** $!${input.description} File name of uploaded file */
    private String newIssueFormAttachmentFileName;

    /** 
     * Get Attachment File name
     *  
     * @return Attachment File name
     */
    public String getNewIssueFormAttachmentFileName() {
       return this.newIssueFormAttachmentFileName;
    }

    /**
     * Set Attachment File name
     *
     * @param newIssueFormAttachmentFileName
     */
    public void setNewIssueFormAttachmentFileName(String newIssueFormAttachmentFileName) {
        this.newIssueFormAttachmentFileName = newIssueFormAttachmentFileName;
    }


    protected void initNewIssueFormPriority() {
        this.newIssueFormPriorityOptions.add(new SelectItem("high", "High"));
        this.newIssueFormPriorityOptions.add(new SelectItem("normal", "Normal"));
        this.newIssueFormPriorityOptions.add(new SelectItem("low", "Low"));
    }

 /** Priority
  *
  *   */
  protected String newIssueFormPriority;
  
  public String getNewIssueFormPriority() {
    return this.newIssueFormPriority;
  }

  public void setNewIssueFormPriority(String newIssueFormPriority) {
    this.newIssueFormPriority = newIssueFormPriority;
  }

  protected List<SelectItem> newIssueFormPriorityOptions = new ArrayList<SelectItem>();

  public List<SelectItem> getNewIssueFormPriorityOptions() {
    return this.newIssueFormPriorityOptions;
  }

  public void setNewIssueFormPriorityOptions(List<SelectItem> newIssueFormPriorityOptions) {
    this.newIssueFormPriorityOptions = newIssueFormPriorityOptions;
  }
    protected void initNewIssueFormAssignee() {
        this.newIssueFormAssigneeOptions.add(new SelectItem("jonathan", "Jon"));
        this.newIssueFormAssigneeOptions.add(new SelectItem("steven", "Steven"));
        this.newIssueFormAssigneeOptions.add(new SelectItem("evan", "Evan"));
        this.newIssueFormAssigneeOptions.add(new SelectItem("nicole", "Nicole"));
        this.newIssueFormAssigneeOptions.add(new SelectItem("vineet", "Vineet"));
        this.newIssueFormAssigneeOptions.add(new SelectItem("will", "Will"));
    }

 /** Assignee
  *
  *   */
  protected String newIssueFormAssignee;
  
  public String getNewIssueFormAssignee() {
    return this.newIssueFormAssignee;
  }

  public void setNewIssueFormAssignee(String newIssueFormAssignee) {
    this.newIssueFormAssignee = newIssueFormAssignee;
  }

  protected List<SelectItem> newIssueFormAssigneeOptions = new ArrayList<SelectItem>();

  public List<SelectItem> getNewIssueFormAssigneeOptions() {
    return this.newIssueFormAssigneeOptions;
  }

  public void setNewIssueFormAssigneeOptions(List<SelectItem> newIssueFormAssigneeOptions) {
    this.newIssueFormAssigneeOptions = newIssueFormAssigneeOptions;
  }
    protected void initNewIssueFormEnvironment() {
        this.newIssueFormEnvironmentOptions.add(new SelectItem("prod", "Production"));
        this.newIssueFormEnvironmentOptions.add(new SelectItem("test", "Testing"));
        this.newIssueFormEnvironmentOptions.add(new SelectItem("dev", "Development"));
    }

 /** Environment
  *
  *   */
  protected String newIssueFormEnvironment;
  
  public String getNewIssueFormEnvironment() {
    return this.newIssueFormEnvironment;
  }

  public void setNewIssueFormEnvironment(String newIssueFormEnvironment) {
    this.newIssueFormEnvironment = newIssueFormEnvironment;
  }

  protected List<SelectItem> newIssueFormEnvironmentOptions = new ArrayList<SelectItem>();

  public List<SelectItem> getNewIssueFormEnvironmentOptions() {
    return this.newIssueFormEnvironmentOptions;
  }

  public void setNewIssueFormEnvironmentOptions(List<SelectItem> newIssueFormEnvironmentOptions) {
    this.newIssueFormEnvironmentOptions = newIssueFormEnvironmentOptions;
  }
 
 
	/**
	 * a convenient method to clear this form
	 */
	protected void clearNewIssueForm() {
		clearNewIssueFormTitle();
		clearNewIssueFormDescription();
		clearNewIssueFormPriority();
		clearNewIssueFormAssignee();
		clearNewIssueFormEnvironment();
		clearNewIssueFormAttachment();
	}

     public void clearNewIssueFormTitle() {
		setNewIssueFormTitle(null);
    }

    public void newIssueFormTitleValidator(javax.faces.context.FacesContext facesContext,
            javax.faces.component.UIComponent component, java.lang.Object value) {
        String valueStr = value.toString();
        
    }
     public void clearNewIssueFormDescription() {
		setNewIssueFormDescription(null);
    }

    public void newIssueFormDescriptionValidator(javax.faces.context.FacesContext facesContext,
            javax.faces.component.UIComponent component, java.lang.Object value) {
        String valueStr = value.toString();
        
    }
     public void clearNewIssueFormPriority() {
		setNewIssueFormPriority(null);
    }

    public void newIssueFormPriorityValidator(javax.faces.context.FacesContext facesContext,
            javax.faces.component.UIComponent component, java.lang.Object value) {
        String valueStr = value.toString();
        
    }
     public void clearNewIssueFormAssignee() {
		setNewIssueFormAssignee(null);
    }

    public void newIssueFormAssigneeValidator(javax.faces.context.FacesContext facesContext,
            javax.faces.component.UIComponent component, java.lang.Object value) {
        String valueStr = value.toString();
        
    }
     public void clearNewIssueFormEnvironment() {
		setNewIssueFormEnvironment(null);
    }

    public void newIssueFormEnvironmentValidator(javax.faces.context.FacesContext facesContext,
            javax.faces.component.UIComponent component, java.lang.Object value) {
        String valueStr = value.toString();
        
    }
     public void clearNewIssueFormAttachment() {
	setNewIssueFormAttachmentContentType(null);
	setNewIssueFormAttachmentInputStream(null);
	setNewIssueFormAttachmentFileName(null);
    }

    public void newIssueFormAttachmentValidator(javax.faces.context.FacesContext facesContext,
            javax.faces.component.UIComponent component, java.lang.Object value) {
        String valueStr = value.toString();
        
    }

 
    /**
     *  Converts any form inputs bound to entities to entities, stores them in the map ready to 
     *  be passed to the service methods
     */
    protected Issue getNewIssueFormIssue() {
         // create a new Issue from input
        Issue newIssue = issueDao.newInstance();

        newIssue.setTitle(toText(newIssueFormTitle));
        newIssue.setDescription(toText(newIssueFormDescription));
        newIssue.setPriority(toText(newIssueFormPriority));
        newIssue.setAssignee(toText(newIssueFormAssignee));
        newIssue.setEnvironment(toText(newIssueFormEnvironment));
        newIssue.getAttachment().update(newIssueFormAttachmentFileName, newIssueFormAttachmentContentType, newIssueFormAttachmentInputStream);
        return newIssue;
    }


 
   /**
    * Save New Issue
    *
    *     * Automatically generated by clickframes
    */
   public abstract NewIssueFormCreateOutcome newIssueFormCreate();




    private static final long serialVersionUID = 1L;


    /**
     * different legal outcomes for Save New Issue 
     * 
     * This page provides a form for submitting a new issue.
     */
     public enum NewIssueFormCreateOutcome {
        /** 
         * Issue Saved
         */ 
        issueSaved    
    }
  }// clickframes::version=1898147573::clickframes